#ifndef F_CAUTEmuTMTCServerC_h
#define F_CAUTEmuTMTCServerC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMCAUTEmuTMTCServerSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, EmuGSDoublePackList, STMTCPackList, STMDoublePackList, SFinalTCPackets, STCPackList };


	friend class CAUTEmuTMTCServer;

	CAUTEmuTMTCServer &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SgiTMTCServer2;
	CEDROOMInterface & SgiTMTCServer;

	enum edroomStateId{I, Ready};

	enum IdTrans{SendTMPacks, Init, ReceiveTCPacks, SendTCPackList,  EDROOMMEMORIA };

	//Constantes



	//Variables

	CDDataBurst &VDataBurst;
	CPackListHandler &VFreePackList;
	int &VnumMensajeTC;
	int &VnumMensajeTM;
	PackPool &VPackListPool;
	CPackListHandler &VRouterFree;
	CPackListHandler &VRouterTC;
	CPackListHandler &VTCPackList;
	CPackListHandler &VTMPackList;


	//Pool

	class CEDROOMPOOLCDTMTCCommServer:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDTMTCCommServer(TEDROOMUInt32 elemCount,CDTMTCCommServer *pMem, TEDROOMBool *pMarks);
		CDTMTCCommServer	* AllocData();
	};
	CEDROOMPOOLCDTMTCCommServer	& CEDROOMPoolCDTMTCCommServer;


	// CONSTRUCTORES

	EDROOMTopContext (CAUTEmuTMTCServer &act, CDDataBurst & EDROOMpVarVDataBurst, CPackListHandler & EDROOMpVarVFreePackList, int & EDROOMpVarVnumMensajeTC, int & EDROOMpVarVnumMensajeTM, PackPool & EDROOMpVarVPackListPool, CPackListHandler & EDROOMpVarVRouterFree, CPackListHandler & EDROOMpVarVRouterTC, CPackListHandler & EDROOMpVarVTCPackList, CPackListHandler & EDROOMpVarVTMPackList, CEDROOMPOOLCDTMTCCommServer & EDROOMpPoolCDTMTCCommServer );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	bool_t	FGetTMPackets(int32_t numeroFichero,byte_t *mensaje);

	bool_t	FGetTCPackets(int32_t numeroFichero,byte_t *mensaje);

	void	FInit();

	void	FInitFreePackPool();

	void	FInitTMFiles();

	void	FIntToChar(int32_t num,byte_t * cConvert);

	void	FReady();

	void	FSendInitRouter();

	void	FSendTCPackList();

	void	FSendTMPackets();

	void	FStoreTCFiles();

	void	FStoreTCFrame(byte_t * frames);

	void	FStoreTCPackets();

	void	FInitTCFiles();


};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	CDDataBurst VDataBurst;
	CPackListHandler VFreePackList;
	int VnumMensajeTC;
	int VnumMensajeTM;
	PackPool VPackListPool;
	CPackListHandler VRouterFree;
	CPackListHandler VRouterTC;
	CPackListHandler VTCPackList;
	CPackListHandler VTMPackList;


	//Pools

	CEDROOMPOOLCDTMTCCommServer	CEDROOMPoolCDTMTCCommServer;


public:

	// CONSTRUCTOR

	EDROOMTopState (CAUTEmuTMTCServer &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Ready

	// ***********************************************************************



	TEDROOMTransId EDROOMReadyllegada();

};


#endif
